package com.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.pojo.OrderSetting;
import com.health.service.OrderSettingService;
import com.health.vo.Result;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    /**
     * 校验体检日期
     */
    @GetMapping("/checkOrderDate")
    public Result checkOrderDate(@DateTimeFormat(pattern = "yyyy-MM-dd") Date orderDate) {
        OrderSetting orderSetting = orderSettingService.findByOrderDate(orderDate);
        if (orderSetting == null) {
            //未设置预约
            return new Result(false, "所选日期无法预约");
        } else if (orderSetting.getReservations() >= orderSetting.getNumber()) {
            //已设置，但是预约已满
            return new Result(false, "所选日期预约已满");
        }

        return new Result(true, "所选日期可以预约");
    }
}
